package dobest.ray.com.jiongjiong.activity.wanttoknow.consult;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.facebook.drawee.view.SimpleDraweeView;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseActivity;
import dobest.ray.com.jiongjiong.views.NavigationBar;
import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;

/**
 * Created by Ray on 2016/3/22.
 * https://github.com/ray0807
 */
public class ConsultOnlineTwoActivity extends BaseActivity implements View.OnClickListener {
    private SimpleDraweeView sdv_photo;
    private Button btn_goto_consult;
    private String token = "jD7El61mvoCEupWhLc2lEEcE+r1yAIlTNS7HpPR6hDjle876OXvI1NEkLsIyZf8uWp0VYR2JeAc8WCQtRKGzlw==";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_consult_on_line_two);
        findViews();
        init();
        addListeners();
    }

    @Override
    public void findViews() {
        navi = (NavigationBar) findViewById(R.id.navi);
        navi.setTitle("在线咨询");
        navi.setBackListener(R.mipmap.img_back, "");
        sdv_photo = (SimpleDraweeView) findViewById(R.id.sdv_photo);
        btn_goto_consult = (Button) findViewById(R.id.btn_goto_consult);
    }

    @Override
    public void init() {
        sdv_photo.setImageURI(Uri.parse("http://www.cnsc8.com/res/tupian_201403/Big_Pic/jBaWwaVTmu.jpg"));

        RongIM.connect(token, new RongIMClient.ConnectCallback() {
            @Override
            public void onTokenIncorrect() {
                showToast("token错误");

            }

            @Override
            public void onSuccess(String s) {
                //s表示userid
                showToast("连接服务器成功s：" + s);
            }

            @Override
            public void onError(RongIMClient.ErrorCode errorCode) {
                showToast("error");
            }
        });
    }

    @Override
    public void addListeners() {
        btn_goto_consult.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent it = null;
        switch (v.getId()) {
            case R.id.btn_goto_consult:
//                it = new Intent(this, ConsultOnlineActivity.class);
                if (RongIM.getInstance() != null) {
                    RongIM.getInstance().startPrivateChat(this, "1", "健康咨询");
                }
                break;
        }
        if (it != null) {
            startActivity(it);
        }
    }
}
